package util;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class tool {
    public static void main(String[] args) {
        tool t = new tool();
        List<classes>list= t.findAll();
        for(classes c:list){
            System.out.println(c);
        }
    }
    //查询所有学生对象
    public List<classes> findAll(){
        List<classes> list = new ArrayList<classes>();
       Connection conn=null;
       Statement stat = null;
        ResultSet res = null;
        try {
            //注册驱动
            //Class.forName("com.mysql.jdbc.Driver");
            //建立连接
//            conn= DriverManager.getConnection("jdbc:mysql:///sun","root","123456");
            conn=JDBCUtils.getConnection();//
            //获取链接
            stat=conn.createStatement();
            //传入SQL查询
            String sql="select * from classes";
            res=stat.executeQuery(sql);
            while (res.next()){
            classes classes = new classes();
            classes.setId(res.getInt("id"));
            classes.setName(res.getString("name"));
            classes.setChinese(res.getInt("chinese"));
            classes.setEnglish(res.getInt("english"));
            classes.setMath(res.getInt("math"));
            list.add(classes);
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {

               JDBCUtils.close(conn,stat,res);
        }
        return list;
    }
}
